package com.primaryedu.ui.app.parentsch;

import com.primaryedu.R;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ParentAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    @SuppressWarnings("unused")
    private Context context;

    private Integer[] imgs = new Integer[]{
            R.drawable.parent_01,
            R.drawable.parent_02,
            R.drawable.parent_03,
            R.drawable.parent_04,
            R.drawable.parent_05,
            R.drawable.parent_06,
    };

    private String[] str = new String[]{
            "问卷调查", "活动投票", "家校共育", "亲子交流", "德育天地", "助力小升初"
    };

    public ParentAdapter(Activity context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return imgs.length;
    }

    @Override
    public Object getItem(int arg0) {
        return str[arg0];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("NewApi")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_menu, null);
            viewHolder.textView = (TextView) convertView.findViewById(R.id.item_text);
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.item_image);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.imageView.setImageResource(imgs[position]);
        viewHolder.textView.setText(str[position]);

        return convertView;
    }

    class ViewHolder {
        ImageView imageView;
        TextView textView;
    }

}
